Did you know/2009
__NOEDITSECTION__ This is an archive of the Did you know? section on the home page for 2009. December 2009 *Vim tutorials has videos illustrating simple and advanced topics. *Searching with /\%>80v.\+ finds the next line longer than 80 characters (after expanding tabs). *Mapping a key to execute :update makes it easy to save the current file, if changed. *If a file from a Mac is garbled, reload it with :e ++ff=mac. *The command :set et|retab expands all tab indents to use spaces. *Typing "+P pastes the clipboard before the cursor and sets mark `[ to the beginning of the pasted text, and mark `] to the end. *With the cursor on an http link, pressing Ctrl-W Ctrl-F uses netrw to open the html source in a new window. *The search /hello/e finds "hello" (like /hello), but puts the cursor at the end of the match. *Some mappings or a substitute will help convert PHP variables from $this_variable_style to $thisVariableStyle. *You can use the git version control system from Vim. *We have an example of a simple vimrc with suggestions for configuring Vim. November 2009 *Vim tutorials has videos illustrating simple and advanced topics. *On Windows, when using PuTTY to execute Vim, you should disable application keypad mode. *Enter :scriptnames to list all scripts run by Vim. *Using :execute allows '|' to separate multiple commands, even those that eat '|'. *Entering :m'}-1 moves the current line to the end of the current paragraph. *You can see what script defined a mapping (say for comma) with :verbose map ,. *Using :noautocmd vimgrep ... will speed up vimgrep. *Under Windows, enter :!start calc to asynchronously execute a GUI program (say calc.exe). *In a script, execute normal-mode commands with a bang (example: normal! gqip) to avoid mappings. *Scripts can use filereadable() to check if a file exists and can be read (example). *Scripts can use readfile() to read all lines from a file (same example). October 2009 *[http://vim.runpaint.org/ Vim Recipes] is a new and free cookbook in PDF and HTML. *Using :set splitright causes a new split window to be on the right. *Using :set lines=50 columns=100 in your vimrc sets the initial window size. *Press I to insert text in multiple lines in a visual block. *Setting 'guifont' in your vimrc can set the font used in gvim. *Clever scripts can show what colors are available for use in Vim. *A command like :e ++enc=cp850 reloads the file using a different encoding. *Enter :windo wincmd K to change a "horizontal list" of windows to a "vertical list". *We have some ideas for moving through camelCaseWords. *Changing the status line color helps to show whether you are in insert or normal mode. *Many cindent options can be configured with 'cinoptions', including continuation lines. September 2009 *[http://vim.runpaint.org/ Vim Recipes] is a new and free cookbook in PDF and HTML. *You can enter a command like :set ft=python to set the filetype for a new buffer. *Typing _ or g_ moves to the first or last non-blank character of the current line. *Use :verbose set ai? cin? cink? cino? si? inde? indk? to see the current indent settings and where they were set. *A great one page summary of color schemes is available. *Typing gwap formats the paragraph without changing the cursor position. *A search (/ \+\ze\t) can highlight spaces that occur before a tab. *Perl subs can be folded if enabled with :let perl_fold = 1 in your vimrc. *The command :%s/\%Vold/new/g changes "old" to "new" in the last visual selection. *A format option like :setl fo=aw2tq can reflow paragraphs while you type. *Using Ctrl-o in an :imap can execute a normal mode command and stay in insert mode. August 2009 *[http://vim.runpaint.org/ Vim Recipes] is a new and free cookbook in PDF and HTML. *Your syntax files may have configurable options. *With au FileType qf ... you can adjust the quickfix window height. *With au CursorHoldI * ... you can exit insert mode when idle. *A sweet regex can exchange adjacent words regardless of separator. *Typing ci( changes text from anywhere inside parentheses (a text object). *Type :v/pattern/d to delete all lines [[VimTip1557|not matching pattern]]. *Make your own dynamic template with eval(). *Temporarily mapping j and k to Ctrl-e and Ctrl-y (and more) makes scrolling text easy. *Using :set statusline+=%{MyFunction()} can show the syntax highlight group in the statusline. *You can use the Vim color schemes in PuTTY. July 2009 *[http://vim.runpaint.org/ Vim Recipes] is a new and free cookbook in PDF and HTML. *An environment variable can be displayed, for example :echo $PATH. *The 'opfunc' option can be used to define your own operator. *A temporary change to the 'grepprg' option allows git grep in Vim. *:pedit myfile opens a file in the preview window; useful for pydoc. *Use :wa to save all modified files (no save if no change). *Use :e .. to list files in the parent directory. *Use :set showcmd to show the size of the visually-selected area. *Press Ctrl-w then o to show only the current window (close others). *Windows users should use the GnuWin32 diff package. *You can search only unfolded text with :set fdo-=search. June 2009 *[http://vim.runpaint.org/ Vim Recipes] is a new and free cookbook in PDF and HTML *The command :cabbrev can expand commands and fix your frequent typos. *In insert mode, typing =strftime("%c") inserts the current date and time. *You can toggle folds open/closed with za. *perldoc can be used to open a Perl module from its module name. *A plugin allows sorting lines based on a visually-selected column. *Under Windows, you can have pl2bat scripts detected as Perl filetype. *Some mappings allow easy move up/down of current line. *Use :set wildchar= wildmenu wildmode=full for a menu to complete buffer/file names. *In some terminals, meta keys are sent as escape sequences which can exit insert mode. *The command :set cursorline highlights the current line. May 2009 *Type gd to jump to the definition of a local variable, or gD for a global variable. *Sort and remove duplicate lines with :sort u ("unique"). *Some code is needed for unique sorting in a script. *Map the Enter key to Esc to quickly exit insert mode. *And map Enter to insert a newline from normal mode. *A mapping can search for the current word in a new window. *It can be easy to cycle through buffers including hidden buffers. *The pastetoggle option should be used when pasting into a terminal. *Commands like :set wrap! wrap? are useful when toggling boolean options. *Use \V to make a regex "very nomagic", or use :sno for a "very nomagic" substitute. April 2009 *[http://www.swaroopch.com/notes/Vim A Byte of Vim is a free ebook on Vim] *Vim 7.2 has been released *Press [ then the Tab key to jump to the first line containing the current keyword. *The 'pastetoggle' option should be used when pasting into console Vim. *Using :set wrap! wrap? is handy to toggle an option and see its value. *A simple map o can insert a newline in normal mode. *Using nr2char() helps convert from "quoted printable" to plain text. *In a regex, \v is "very magic" (all characters except a-zA-Z0-9_ have special meaning). *The 'binary' and 'eol' options can help preserve a missing final end-of-line. *Using the ftplugin directory helps keep your vimrc clean. *The command :scriptnames lists all scripts that have been sourced (more). *Vim Doclet is a Doclet for Java that generates documentation in Vim Help format. March 2009 *[http://www.swaroopch.com/notes/Vim A Byte of Vim is a free ebook on Vim] *Vim 7.2 has been released *Press to [[VimTip9|display all lines] containing the current variable. *Press gF to jump to a specified line number in a file. *A mapping allows jumping sections in Latex documents. *Using a mapping (with :update) allows quick saves of the current buffer, if changed. *It's easy to replace the current word with the last yanked text. *A keymap allows entry of characters that are not available on your keyboard. *The command :e $MYVIMRC will edit your vimrc file. *You can add a dashed line under a title. *Some scripting allows fast changes to your font size. *Using :set foldlevel=20 means all folds are open when a file is opened. February 2009 *[http://www.swaroopch.com/notes/Vim A Byte of Vim is a free ebook on Vim] *Vim 7.2 has been released *Type to [[VimTip9|display the definition] of the current variable, or for a macro. *The :set hlsearch command [[VimTip14|highlights all search hits]; use :noh to temporarily switch off. *You may be able to recover lost text if the power fails while you are editing. *Use digraphs to enter special characters: in insert mode, press Ctrl-K then Co for ©, or Ctrl-K then Pd for £. *The quickfix list can be used to fold away lines with no errors/matches. *The 'whichwrap' option controls whether the backspace and cursor keys wrap to the previous/next line. *Manual fold markers can be hidden using the Ignore highlighting group. *Some mappings allow Ctrl-S to save the current file, or a new file. *It's useful to map a key for quicker access to recorded macros. January 2009 *[http://www.swaroopch.com/notes/Vim A Byte of Vim is a free ebook on Vim] *Vim 7.2 has been released *You can keep your window layout by deleting a buffer without closing the window. *A script makes it easy to move lines up or down. *We have lots of opinions on the perfect programming font. *gg"+yG is one way to copy the entire buffer to the clipboard. *It is possible to run native-Windows Vim from cygwin without a wrapper. *Some mappings allow you to quickly add or delete empty lines. *A FocusLost autocommand is one way to auto-save files when the focus is lost. *We have an extensive tutorial on mapping keys. *With a suitable definition for b:match_words, you can fold a C# region. Category:VimInformation